package va_btree;

import btree.*;
import bufmgr.HashEntryNotFoundException;
import bufmgr.InvalidFrameNumberException;
import bufmgr.PageNotReadException;
import bufmgr.PageUnpinnedException;
import bufmgr.ReplacerException;
import global.AttrType;
import global.IndexType;
import global.Vector100Dtype;
import heap.*;
import index.IndexException;
import iterator.*;
import va.BaseNNIndexScan;
import va.BitSet;
import va.Range;
import va.VAEntry;
import va_file.VAFile;

import java.io.IOException;

public class NNBTIndexScan extends BaseNNIndexScan {

    public NNBTIndexScan(IndexType index,
                           String relName,
                           String indexName,
                           AttrType[] types,
                           short[] str_sizes,
                           int noInFields,
                           int noOutFields,
                           FldSpec[] outFields,
                           CondExpr[] selects,
                           int fldNum,
                           Vector100Dtype target,
                           int count,
                           int noOfBits) throws IndexException, HFException, HFBufMgrException, HFDiskMgrException, IOException, InvalidTupleSizeException, PinPageException, IteratorException, KeyNotMatchException, UnpinPageException, ConstructPageException, GetFileEntryException, AddFileEntryException, PageUnpinnedException, InvalidFrameNumberException, HashEntryNotFoundException, ReplacerException, InvalidTypeException, FileScanException, TupleUtilsException, InvalidRelation, JoinsException, PageNotReadException, PredEvalException, UnknowAttrType, FieldNumberOutOfBoundException, WrongPermat {

        super(index, relName, indexName, types, str_sizes, noInFields, noOutFields, outFields, selects, fldNum, target, count, noOfBits);

        VABTreeFile file = new VABTreeFile(indexName, noOfBits);
        VABTreeScan scan = new VABTreeScan(file);

       /* String lowKey = "";
        String highKey = "";
        for (int i = 0; i < 100; i++) {
            // Just set the low and high key to the highest and lowest possible
            for (int j = 0; j < noOfBits; j++) {
                lowKey += "0";
                highKey += "1";
            }
        }*/

        //Use the scan object to get the RIDs
        //this.rids = scan.VABTreeNNScan(new StringKey(lowKey), new StringKey(highKey), target, count);
        this.rids = scan.VABTreeNNScan(null, null, target, count);
        scan.close();
        file.close();
    }

}
